local skel = fk.CreateSkill{
  name = "fm__dimeng",
  attached_skill_name = "fm__dimeng_viewas&"
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["fm__dimeng"] = "缔盟",
  [":fm__dimeng"] = "出牌阶段限一次，你可以选择两名其他角色，直到你下个回合开始时，其可以于其出牌阶段使用对方的手牌。",
  ["@fm__dimeng"] = "缔盟",

  ["$fm__dimeng1"] = "协心齐同，与结盟好。",
  ["$fm__dimeng2"] = "戮力一心，分灾共庆。",
}
---@type ActiveSkillSpec
local dimeng = {
  anim_type = "control",
  target_num = 2,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected < 2 and to_select ~= player
  end,
  can_use = function (self, player)
    return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function (self, room, effect)
    local tos = effect.tos
    if #tos == 2 and tos[1] ~= tos[2] then
      for _, p in ipairs(room:getAlivePlayers()) do
        room:setPlayerMark(p, "fm__dimeng", 0)
        room:setPlayerMark(p, "@fm__dimeng", 0)
        room:handleAddLoseSkills(p, "-"..skel.attached_skill_name, nil, false, false)
      end
      room:setPlayerMark(tos[1], "fm__dimeng", tos[2].id)
      room:setPlayerMark(tos[1], "@fm__dimeng", tos[2].general)
      room:handleAddLoseSkills(tos[1], skel.attached_skill_name, nil, false, false)
      room:setPlayerMark(tos[2], "fm__dimeng", tos[1].id)
      room:setPlayerMark(tos[2], "@fm__dimeng", tos[1].general)
      room:handleAddLoseSkills(tos[2], skel.attached_skill_name, nil, false, false)
    end
  end
}
---@type TrigSkelSpec<TurnFunc>
local dimeng_delay = {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true, true) and player == target
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      room:setPlayerMark(p, "fm__dimeng", 0)
      room:setPlayerMark(p, "@fm__dimeng", 0)
      room:handleAddLoseSkills(p, "-"..skel.attached_skill_name, nil, false, false)
    end
  end
}
skel:addEffect("active", dimeng)
skel:addEffect(fk.TurnStart, dimeng_delay)
skel:addEffect(fk.Death, dimeng_delay)
return skel